# -*- coding: UTF-8 -*-
"a itchat momule"
__author__ = 'xiang'

import itchat, time

class weixin_me :
    def __init__(self):
        self.txts = 'Hello I am a Robot'
        self.send_user = 'filehelper'
        self.dict_user={}
        self.number = 1

    def send_msg(self):
        dict_user = self.dict_user
        input_name = input('请输入微信联系人昵称,非本人备注:')
        txts = self.txts
        friendList = itchat.get_friends(update=True)[1:]
        for friend in friendList:
            nice=friend['DisplayName'] or friend['NickName']
            User=friend['UserName']
            temp_user={nice:User}
            dict_user.update(temp_user.items())
        try :
            send_user=(dict_user.get(input_name))
            print(send_user)
            result=itchat.send(txts,send_user)
            print(result)
        except Exception as e :
            raise

    def weixin_start(self):
        itchat.auto_login(hotReload=True)
        number = self.number
        txts = self.txts
        while number < 5 :
            number += 1
            self.send_msg()
            time.sleep(1)

if __name__ == '__main__':
    me = weixin_me()
    me.weixin_start()
